package org.geektimes.configuration.microprofile.config.source;

import org.eclipse.microprofile.config.spi.ConfigSource;
import org.geektimes.configuration.microprofile.config.constant.ConfigConstant;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;

public class OSEnvironmentPropertiesConfigSource implements ConfigSource {

    private Map<String, String> properties;

    public OSEnvironmentPropertiesConfigSource() {
        properties = new HashMap<>();
        System.getenv().forEach((prop, val) -> properties.put(prop, val));
    }

    @Override
    public Map<String, String> getProperties() {
        return this.properties;
    }

    @Override
    public Set<String> getPropertyNames() {
        return this.properties.keySet();
    }


    @Override
    public String getValue(String propertyName) {
        return this.getProperties().get(propertyName);
    }

    @Override
    public String getName() {
        return "OS Environment Properties";
    }

    @Override
    public int getOrdinal() {
        return ConfigConstant.OS_ENV_ORDINAL;
    }
}
